package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.PostMapper;
import com.aaa.hospital.pojo.domain.Post;
import com.aaa.hospital.pojo.query.PostQuery;
import com.aaa.hospital.pojo.vo.PostVO;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: danghui
 * @Date: 2022/2/21 13:59
 * @Description: TODO
 */
@Service
public class PostServiceImpl implements PostService {
    @Autowired
    private PostMapper postMapper;
    @Override
    public AjaxResult queryPost(PostQuery query) {
        List<Post> posts = postMapper.queryPost(query);
        Long along = postMapper.queryPostTotal(query);
        HashMap<Object, Object> data = new HashMap<>();
        data.put("currentData",posts);
        data.put("totalCount",along);
        return AjaxResult.success(data);
    }

    @Override
    public AjaxResult deletePost(Integer id) {
        int i = postMapper.deletePost(id);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult addPost(PostVO postVO) {
        int i = postMapper.addPost(postVO);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult getPost(Integer id) {
        PostVO post = postMapper.getPost(id);
        return AjaxResult.success(post);
    }

    @Override
    public AjaxResult updatePost(PostVO postVO) {
        int i = postMapper.updatePost(postVO);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }
}
